import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;




@WebServlet("/index")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //因为是跳转到的页面，所以此处获取session是获取之前的，用false
        HttpSession session = req.getSession(false);
        //获取session里面保存的数据
        String username = (String) session.getAttribute("username");
        String password = (String) session.getAttribute("password");
        Integer count = (Integer) session.getAttribute("count");
        count+=1;
        //把自增之后的count加入到会话中
        session.setAttribute("count",count);

        resp.setContentType("text/html;charset=utf-8");

        resp.getWriter().write("<h3>欢迎您的第"+count +"次登录</h3><br>");
        resp.getWriter().write("用户名："+username+"<br>");
        resp.getWriter().write("密码："+password+"<br>");


    }
}
